﻿using SystemModule;

namespace M2Server
{
    public partial class TPlayObject
    {
        /// <summary>
        /// 发送删除挑战框中物品后,给客户端更新
        /// </summary>
        /// <param name="UserItem"></param>
        private unsafe void SendDelChallengeItem(TUserItem UserItem)
        {
            TStdItem StdItem;
            TClientItem ClientItem = null;
            TOClientItem* OClientItem = null;
            string sUserItemName;
            SendDefMessage(Grobal2.SM_CHALLENGEDELITEM_OK, 0, 0, 0, 0, "");
            if (m_ChallengeCreat != null)
            {
                if (m_ChallengeCreat.m_nSoftVersionDateEx == 0)
                {
                    StdItem = M2Share.UserEngine.GetStdItem(UserItem.wIndex);
                    if (StdItem != null)
                    {
                        M2Share.CopyStdItemToOStdItem(StdItem, &OClientItem->s);// 取自定义物品名称
                        sUserItemName = "";
                        if (UserItem.btValue[13] == 1)
                        {
                            sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                        }
                        if (sUserItemName != "")
                        {
                            HUtil32.StrToSByteArry(sUserItemName, OClientItem->s.Name, 14, ref OClientItem->s.NameLen);
                        }
                        OClientItem->MakeIndex = UserItem.MakeIndex;
                        OClientItem->Dura = UserItem.Dura;
                        OClientItem->DuraMax = UserItem.DuraMax;
                    }
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CHALLENGEREMOTEDELITEM, this.m_ActorsId, 0, 0, 1, 0);
                    byte[] data = new byte[sizeof(TOClientItem)];
                    fixed (byte* pb = data)
                    {
                        *(TOClientItem*)pb = *OClientItem;
                    }
                    m_ChallengeCreat.SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(data, sizeof(TOClientItem)));
                }
                else
                {
                    StdItem = M2Share.UserEngine.GetStdItem(UserItem.wIndex);
                    if (StdItem != null)
                    {
                        ClientItem.s = StdItem;// 取自定义物品名称
                        sUserItemName = "";
                        if (UserItem.btValue[13] == 1)
                        {
                            sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                        }
                        if (sUserItemName != "")
                        {
                            ClientItem.s.Name = sUserItemName;
                        }
                        if (UserItem.btValue[12] == 1) // 物品发光
                        {
                            ClientItem.s.Reserved1 = 1;
                        }
                        else
                        {
                            ClientItem.s.Reserved1 = 0;
                        }
                        if ((StdItem.StdMode == 60) && (StdItem.Shape != 0))  // 酒类,除烧酒外
                        {
                            if (UserItem.btValue[0] != 0)
                            {
                                ClientItem.s.AC = UserItem.btValue[0];// 酒的品质
                            }
                            if (UserItem.btValue[1] != 0)
                            {
                                ClientItem.s.MAC = UserItem.btValue[1]; // 酒的酒精度
                            }
                        }
                        ClientItem.MakeIndex = UserItem.MakeIndex;
                        ClientItem.Dura = UserItem.Dura;
                        ClientItem.DuraMax = UserItem.DuraMax;
                    }
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CHALLENGEREMOTEDELITEM, this.m_ActorsId, 0, 0, 1, 0);
                    m_ChallengeCreat.SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer<TClientItem>(ClientItem));
                }
                m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                m_ChallengeLastTick = HUtil32.GetTickCount();
            }
        }

        /// <summary>
        /// 发送抵押的挑战物品
        /// </summary>
        /// <param name="UserItem"></param>
        private unsafe void SendAddChallengeItem(TUserItem UserItem)
        {
            TStdItem StdItem;
            TStdItem StdItem80;
            TClientItem ClientItem = null;
            TOClientItem* OClientItem = null;
            string sUserItemName;
            SendDefMessage(Grobal2.SM_CHALLENGEADDITEM_OK, 0, 0, 0, 0, "");
            if (m_ChallengeCreat != null)
            {
                if (m_ChallengeCreat.m_nSoftVersionDateEx == 0)
                {
                    StdItem = M2Share.UserEngine.GetStdItem(UserItem.wIndex);
                    if (StdItem != null)
                    {
                        StdItem80 = StdItem;// 取自定义物品名称
                        sUserItemName = "";
                        if (UserItem.btValue[13] == 1)
                        {
                            sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                        }
                        if (sUserItemName != "")
                        {
                            StdItem80.Name = sUserItemName;
                        }
                        M2Share.ItemUnit.GetItemAddValue(UserItem, StdItem80);
                        M2Share.CopyStdItemToOStdItem(StdItem80, &OClientItem->s);
                        OClientItem->MakeIndex = UserItem.MakeIndex;
                        OClientItem->Dura = UserItem.Dura;
                        OClientItem->DuraMax = UserItem.DuraMax;
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CHALLENGEREMOTEADDITEM, this.m_ActorsId, 0, 0, 1, 0);
                        byte[] data = new byte[sizeof(TOClientItem)];
                        fixed (byte* pb = data)
                        {
                            *(TOClientItem*)pb = *OClientItem;
                        }
                        m_ChallengeCreat.SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(data, sizeof(TOClientItem)));
                        m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                        m_ChallengeLastTick = HUtil32.GetTickCount();
                    }
                }
                else
                {
                    StdItem = M2Share.UserEngine.GetStdItem(UserItem.wIndex);
                    if (StdItem != null)
                    {
                        StdItem80 = StdItem;
                        M2Share.ItemUnit.GetItemAddValue(UserItem, StdItem80);// 取自定义物品名称
                        sUserItemName = "";
                        if (UserItem.btValue[13] == 1)
                        {
                            sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                        }
                        if (sUserItemName != "")
                        {
                            StdItem80.Name = sUserItemName;
                        }
                        if (UserItem.btValue[12] == 1)// 物品发光
                        {
                            StdItem80.Reserved1 = 1;
                        }
                        else
                        {
                            StdItem80.Reserved1 = 0;
                        }
                        if ((StdItem.StdMode == 60) && (StdItem.Shape != 0))// 酒类,除烧酒外
                        {
                            if (UserItem.btValue[0] != 0)
                            {
                                ClientItem.s.AC = UserItem.btValue[0];// 酒的品质
                            }
                            if (UserItem.btValue[1] != 0)
                            {
                                ClientItem.s.MAC = UserItem.btValue[1]; // 酒的酒精度
                            }
                        }
                        ClientItem.s = StdItem80;
                        ClientItem.MakeIndex = UserItem.MakeIndex;
                        ClientItem.Dura = UserItem.Dura;
                        ClientItem.DuraMax = UserItem.DuraMax;
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CHALLENGEREMOTEADDITEM, this.m_ActorsId, 0, 0, 1, 0);
                        m_ChallengeCreat.SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer<TClientItem>(ClientItem));
                        m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                        m_ChallengeLastTick = HUtil32.GetTickCount();
                    }
                }
            }
        }

        // 判断玩家是否面对面,是则弹出抵物品窗口
        private  void ClientChallenge()
        {
            TBaseObject BaseObject;
            TPlayObject PlayObject;
            if (m_boChallengeing || (m_ChallengeCreat != null))
            {
                return;
            }
            // 如果正在挑战则退出
            if (HUtil32.GetTickCount() - m_ChallengeLastTick < 3000)
            {
                // '请稍后再挑战'
                this.SendMsg(M2Share.g_ManageNPC, Grobal2.RM_MENU_OK, 0, this.m_ActorsId, 0, 0, GameMsgDef.g_sPleaseTryChallengeLaterMsg);
                return;
            }
            BaseObject = this.GetPoseCreate();// 取面前对像
            if ((BaseObject != null) && (BaseObject != this) && (BaseObject.m_btRaceServer == Grobal2.RC_PLAYOBJECT))
            {
                PlayObject = ((BaseObject) as TPlayObject);
                if ((PlayObject != null) && (PlayObject.GetPoseCreate() == this))
                {
                    ((this) as TPlayObject).OpenChallengeDlg(PlayObject);// 打开挑战抵押物品窗口
                    PlayObject.OpenChallengeDlg(this);// 打开挑战抵押物品窗口
                }
                else
                {
                    SendDefMessage(Grobal2.SM_CHALLENGE_FAIL, 0, 0, 0, 0, "");
                }
            }
            else
            {
                SendDefMessage(Grobal2.SM_CHALLENGE_FAIL, 0, 0, 0, 0, "");
            }
        }

        // 判断玩家是否面对面,是则弹出抵物品窗口
        // 打开挑战抵押物品窗口
        private  void OpenChallengeDlg(TPlayObject PlayObject)
        {
            m_boChallengeing = true;
            m_ChallengeCreat = PlayObject;
            GetBackChallengeItems();
            SendDefMessage(Grobal2.SM_CHALLENGEMENU, 0, 0, 0, 0, m_ChallengeCreat.m_sCharName);
            m_ChallengeLastTick = HUtil32.GetTickCount();
        }

        /// <summary>
        /// 取回之前抵押物品
        /// </summary>
        public unsafe void GetBackChallengeItems()
        {
            TUserItem UserItem;
            if (m_ChallengeItemList.Count > 0)
            {
                for (int i = 0; i < m_ChallengeItemList.Count; i++)
                {
                    UserItem = m_ChallengeItemList[i];
                    if (UserItem != null)
                    {
                        this.m_ItemList.Add(UserItem);
                        SendAddItem(UserItem);
                    }
                }
            }
            m_ChallengeItemList.Clear();
            this.m_nGold += m_nChallengeGolds;
            m_nChallengeGolds = 0;
            m_nGAMEDIAMOND += m_nChallengeGAMEDIAMOND;
            m_nChallengeGAMEDIAMOND = 0;
            m_boChallengeOK = false;
        }

        // 打开挑战抵押物品窗口
        // 客户端增加抵押物品到挑战框中
        private  void ClientAddChallengeItem(int nItemIdx, string sItemName)
        {
            bool bo11;
            TUserItem UserItem;
            string sUserItemName;
            if ((m_ChallengeCreat == null) || !m_boChallengeing)
            {
                return;
            }
            m_boCanQueryBag = true;// 增加挑战物品时,不能刷新包裹
            try
            {
                if (sItemName.IndexOf(" ") >= 0)
                {
                    // 折分物品名称(信件物品的名称后面加了使用次数)
                    HUtil32.GetValidStr3(sItemName, ref sItemName, new string[] { " " });
                }
                bo11 = false;
                if (!m_ChallengeCreat.m_boChallengeOK)
                {
                    for (int i = this.m_ItemList.Count - 1; i >= 0; i--)
                    {
                        if (this.m_ItemList.Count <= 0)
                        {
                            break;
                        }
                        UserItem = this.m_ItemList[i];
                        if (UserItem == null)
                        {
                            continue;
                        }
                        if (UserItem.MakeIndex == nItemIdx)
                        {
                            // 取自定义物品名称
                            sUserItemName = "";
                            if (UserItem.btValue[13] == 1)
                            {
                                sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                            }
                            if (sUserItemName == "")
                            {
                                sUserItemName = M2Share.UserEngine.GetStdItemName(UserItem.wIndex);
                            }
                            if (((sUserItemName).ToLower().CompareTo((sItemName).ToLower()) == 0) && (m_ChallengeItemList.Count < 5))
                            {
                                if (this.CheckItemValue(UserItem, 1)) // 禁止交易
                                {
                                    break;
                                }
                                else if (this.PlugOfCheckCanItem(1, sUserItemName, false, 0, 0)) // 禁止物品规则(管理插件功能)
                                {
                                    break;
                                }
                                m_ChallengeItemList.Add(UserItem);
                                this.SendAddChallengeItem(UserItem); // 发送抵押的挑战物品
                                //((this) as TPlayObject).SendAddChallengeItem(UserItem);
                                this.m_ItemList.RemoveAt(i);
                                ClearCopyItem(0, UserItem.wIndex, UserItem.MakeIndex);// 清理包裹和仓库复制物品
                                bo11 = true;
                                break;
                            }
                        }
                    }
                }
                if (!bo11)
                {
                    SendDefMessage(Grobal2.SM_CHALLENGEADDITEM_FAIL, 0, 0, 0, 0, "");
                }
            }
            finally
            {
                m_boCanQueryBag = false;// 增加挑战物品时,不能刷新包裹
            }
        }

        // 客户端增加抵押物品到挑战框中
        // 客户端删除抵押的挑战物品
        private  void ClientDelChallengeItem(int nItemIdx, string sItemName)
        {
            bool bo11;
            TUserItem UserItem;
            string sUserItemName;
            if ((m_ChallengeCreat == null) || !m_boChallengeing)
            {
                return;
            }
            if (sItemName.IndexOf(" ") >= 0)
            {
                // 折分物品名称(信件物品的名称后面加了使用次数)
                HUtil32.GetValidStr3(sItemName, ref sItemName, new string[] { " " });
            }
            bo11 = false;
            if (!m_ChallengeCreat.m_boChallengeOK)
            {
                for (int i = m_ChallengeItemList.Count - 1; i >= 0; i--)
                {
                    if (m_ChallengeItemList.Count <= 0)
                    {
                        break;
                    }
                    UserItem = (TUserItem)m_ChallengeItemList[i];
                    if (UserItem == null)
                    {
                        continue;
                    }
                    if (UserItem.MakeIndex == nItemIdx)
                    {
                        // 取自定义物品名称
                        sUserItemName = "";
                        if (UserItem.btValue[13] == 1)
                        {
                            sUserItemName = M2Share.ItemUnit.GetCustomItemName(UserItem.MakeIndex, UserItem.wIndex);
                        }
                        if (sUserItemName == "")
                        {
                            sUserItemName = M2Share.UserEngine.GetStdItemName(UserItem.wIndex);
                        }
                        if ((sUserItemName).ToLower().CompareTo((sItemName).ToLower()) == 0)
                        {
                            this.m_ItemList.Add(UserItem);
                            this.SendDelChallengeItem(UserItem);// 发送删除抵押的挑战物品
                            //((this) as TPlayObject).SendDelChallengeItem(UserItem); 
                            m_ChallengeItemList.RemoveAt(i);
                            bo11 = true;
                            break;
                        }
                    }
                }
            }
            if (!bo11)
            {
                SendDefMessage(Grobal2.SM_CHALLENGEDELITEM_FAIL, 0, 0, 0, 0, "");
            }
        }

        /// <summary>
        /// 挑战取消
        /// </summary>
        private  void ChallengeCancel()
        {
            if (!m_boChallengeing)
            {
                return;
            }
            m_boChallengeing = false;
            SendDefMessage(Grobal2.SM_CHALLENGECANCEL, 0, 0, 0, 0, "");
            if (m_ChallengeCreat != null)
            {
                m_ChallengeCreat.ChallengeCancel();
            }
            m_ChallengeCreat = null;
            GetBackChallengeItems();
            this.SysMsg(GameMsgDef.g_sChallengeActionCancelMsg, TMsgColor.c_Green, TMsgType.t_Hint);// '挑战取消'
            m_ChallengeLastTick = HUtil32.GetTickCount();
        }

        /// <summary>
        /// 客户端取消挑战
        /// </summary>
        private  void ClientCancelChallenge()
        {
            ChallengeCancel();
        }

        /// <summary>
        /// 客户端把金币放到挑战框中
        /// </summary>
        /// <param name="nGold"></param>
        private  void ClientChangeChallengeGold(int nGold)
        {
            bool bo09;
            // 禁止取回放入挑战栏内的金币
            if ((m_nChallengeGolds > 0) && M2Share.g_Config.boCanNotGetBackDeal)
            {
                this.SendMsg(M2Share.g_ManageNPC, Grobal2.RM_MENU_OK, 0, this.m_ActorsId, 0, 0, GameMsgDef.g_sChallengeItemsDenyGetBackMsg);
                SendDefMessage(Grobal2.SM_CHALLENGEDELITEM_FAIL, 0, 0, 0, 0, "");
                return;
            }
            if (nGold < 0)
            {
                SendDefMessage(Grobal2.SM_CHALLENCHGGOLD_FAIL, m_nChallengeGolds, (ushort)HUtil32.LoWord(this.m_nGold), (ushort)HUtil32.HiWord(this.m_nGold), 0, "");
                return;
            }
            bo09 = false;
            if ((m_ChallengeCreat != null) && (this.GetPoseCreate() == m_ChallengeCreat))
            {
                if (!m_ChallengeCreat.m_boChallengeOK)
                {
                    if ((this.m_nGold + m_nChallengeGolds) >= nGold)
                    {
                        this.m_nGold = (this.m_nGold + m_nChallengeGolds) - nGold;
                        m_nChallengeGolds = nGold;
                        SendDefMessage(Grobal2.SM_CHALLENCHGGOLD_OK, m_nChallengeGolds, (ushort)HUtil32.LoWord(this.m_nGold), (ushort)HUtil32.HiWord(this.m_nGold), 0, "");
                        m_ChallengeCreat.SendDefMessage(Grobal2.SM_CHALLENREMOTECHGGOLD, m_nChallengeGolds, 0, 0, 0, "");
                        m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                        bo09 = true;
                        m_ChallengeLastTick = HUtil32.GetTickCount();
                    }
                }
            }
            if (!bo09)
            {
                SendDefMessage(Grobal2.SM_CHALLENCHGGOLD_FAIL, m_nChallengeGolds, (ushort)HUtil32.LoWord(this.m_nGold), (ushort)HUtil32.HiWord(this.m_nGold), 0, "");
            }
        }

        /// <summary>
        /// 客户端把金刚石放到挑战框中
        /// </summary>
        /// <param name="nDIAMOND"></param>
        private  void ClientChangeChallengeDIAMOND(int nDIAMOND)
        {
            bool bo09;
            if (nDIAMOND < 0)
            {
                SendDefMessage(Grobal2.SM_CHALLENCHGDIAMOND_FAIL, m_nChallengeGAMEDIAMOND, (ushort)HUtil32.LoWord(m_nGAMEDIAMOND), (ushort)HUtil32.HiWord(m_nGAMEDIAMOND), 0, "");
                return;
            }
            bo09 = false;
            if ((m_ChallengeCreat != null) && (this.GetPoseCreate() == m_ChallengeCreat))
            {
                if (!m_ChallengeCreat.m_boChallengeOK)
                {
                    if ((m_nGAMEDIAMOND + m_nChallengeGAMEDIAMOND) >= nDIAMOND)
                    {
                        m_nGAMEDIAMOND = (m_nGAMEDIAMOND + m_nChallengeGAMEDIAMOND) - nDIAMOND;
                        m_nChallengeGAMEDIAMOND = nDIAMOND;
                        SendDefMessage(Grobal2.SM_CHALLENCHGDIAMOND_OK, m_nChallengeGAMEDIAMOND, (ushort)HUtil32.LoWord(m_nGAMEDIAMOND), (ushort)HUtil32.HiWord(m_nGAMEDIAMOND), 0, "");
                        m_ChallengeCreat.SendDefMessage(Grobal2.SM_CHALLENREMOTECHGDIAMOND, m_nChallengeGAMEDIAMOND, 0, 0, 0, "");
                        m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                        bo09 = true;
                        m_ChallengeLastTick = HUtil32.GetTickCount();
                    }
                }
            }
            if (!bo09)
            {
                SendDefMessage(Grobal2.SM_CHALLENCHGDIAMOND_FAIL, m_nChallengeGAMEDIAMOND, (ushort)HUtil32.LoWord(m_nGAMEDIAMOND), (ushort)HUtil32.HiWord(m_nGAMEDIAMOND), 0, "");
            }
        }

        /// <summary>
        /// 挑战抵押物品结束
        /// </summary>
        private  void ClientChallengeEnd()
        {
            bool bo11;
            m_boChallengeOK = true;
            if (m_ChallengeCreat == null)
            {
                return;
            }
            if (((HUtil32.GetTickCount() - m_ChallengeLastTick) < 1000) || ((HUtil32.GetTickCount() - m_ChallengeCreat.m_ChallengeLastTick) < 1000))
            {
                this.SysMsg(GameMsgDef.g_sChallengeOKTooFast, TMsgColor.c_Red, TMsgType.t_Hint); // '过早按了确定按钮。'
                ChallengeCancel();
                return;
            }
            if (m_ChallengeCreat.m_boChallengeOK)
            {
                bo11 = true;
                if ((Grobal2.MAXBAGITEM - this.m_ItemList.Count) < m_ChallengeCreat.m_ChallengeItemList.Count)
                {
                    bo11 = false;
                    this.SysMsg(GameMsgDef.g_sChallengeYourBagSizeTooSmall, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                if ((this.m_nGoldMax - this.m_nGold) < m_ChallengeCreat.m_nChallengeGolds)
                {
                    this.SysMsg(GameMsgDef.g_sChallengeYourGoldLargeThenLimit, TMsgColor.c_Red, TMsgType.t_Hint);
                    bo11 = false;
                }
                if ((Grobal2.MAXBAGITEM - m_ChallengeCreat.m_ItemList.Count) < m_ChallengeItemList.Count)
                {
                    this.SysMsg(GameMsgDef.g_sChallengeHumanBagSizeTooSmall, TMsgColor.c_Red, TMsgType.t_Hint);
                    bo11 = false;
                }
                if ((m_ChallengeCreat.m_nGoldMax - m_ChallengeCreat.m_nGold) < m_nChallengeGolds)
                {
                    this.SysMsg(GameMsgDef.g_sChallengeHumanGoldLargeThenLimit, TMsgColor.c_Red, TMsgType.t_Hint);
                    bo11 = false;
                }
                if (bo11)
                {
                    SendDefMessage(Grobal2.SM_CLOSECHALLENGE, 0, 0, 0, 0, "");// 关闭挑战抵押物品窗口
                    m_ChallengeCreat.SendDefMessage(Grobal2.SM_CLOSECHALLENGE, 0, 0, 0, 0, "");// 关闭挑战抵押物品窗口
                    if (M2Share.g_FunctionNPC != null)
                    {
                        M2Share.g_FunctionNPC.GotoLable(this, "@Challenge", false);// 进入触发段(传送挑战地图)
                    }
                }
                else
                {
                    ChallengeCancel();
                }
            }
            else
            {
                this.SysMsg(GameMsgDef.g_sYouChallengeOKMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                m_ChallengeCreat.SysMsg(GameMsgDef.g_sPoseChallengeOKMsg, TMsgColor.c_Green, TMsgType.t_Hint);
            }
        }

        /// <summary>
        /// 胜方取得物品
        /// </summary>
        public unsafe void WinGetChallengeItems()
        {
            TUserItem UserItem;
            TStdItem StdItem;
            if (m_ChallengeCreat != null)
            {
                m_ChallengeCreat.m_boChallengeing = false;
                m_boChallengeing = false;
                m_ChallengeCreat.m_ChallengeTime = 0;
                m_ChallengeTime = 0;
                if (m_ChallengeCreat.m_ChallengeItemList.Count > 0)
                {
                    for (int i = 0; i < m_ChallengeCreat.m_ChallengeItemList.Count; i++)
                    {
                        UserItem = m_ChallengeCreat.m_ChallengeItemList[i];
                        if (UserItem != null)
                        {
                            StdItem = M2Share.UserEngine.GetStdItem(UserItem.wIndex);
                            if (StdItem != null)
                            {
                                if (StdItem.NeedIdentify == 1)
                                {
                                    M2Share.AddGameDataLog("36" + "\09" + this.m_sMapName + "\09" + (this.m_nCurrX).ToString() + "\09" +
                                        (this.m_nCurrY).ToString() + "\09" + this.m_sCharName + "\09" + StdItem.Name + "\09" + (UserItem.MakeIndex).ToString()
                                        + "\09" + "(" + (HUtil32.LoWord(StdItem.DC)).ToString() + "/" + (HUtil32.HiWord(StdItem.DC)).ToString() + ")" + "(" + (HUtil32.LoWord(StdItem.MC)).ToString()
                                        + "/" + (HUtil32.HiWord(StdItem.MC)).ToString() + ")" + "(" + (HUtil32.LoWord(StdItem.SC)).ToString() + "/" + (HUtil32.HiWord(StdItem.SC)).ToString() + ")"
                                        + "(" + (HUtil32.LoWord(StdItem.AC)).ToString() + "/" + (HUtil32.HiWord(StdItem.AC)).ToString() + ")" + "(" + (HUtil32.LoWord(StdItem.MAC)).ToString() + "/"
                                        + (HUtil32.HiWord(StdItem.MAC)).ToString() + ")" + (UserItem.btValue[0]).ToString() + "/" + (UserItem.btValue[1]).ToString() + "/"
                                        + (UserItem.btValue[2]).ToString() + "/" + (UserItem.btValue[3]).ToString() + "/" + (UserItem.btValue[4]).ToString() + "/" +
                                        (UserItem.btValue[5]).ToString() + "/" + (UserItem.btValue[6]).ToString() + "/" + (UserItem.btValue[7]).ToString() + "/" +
                                        (UserItem.btValue[8]).ToString() + "/" + (UserItem.btValue[14]).ToString() + "\09" + m_ChallengeCreat.m_sCharName);
                                }
                            }
                            if (IsEnoughBag())// 人物的包裹是否满了
                            {
                                ClearCopyItem(0, UserItem.wIndex, UserItem.MakeIndex);// 清理包裹和仓库复制物品
                                this.m_ItemList.Add(UserItem);
                                SendAddItem(UserItem);
                            }
                            else if (m_StorageItemList.Count < Grobal2.MAXBAGITEM)  // 保存到仓库里
                            {
                                ClearCopyItem(1, UserItem.wIndex, UserItem.MakeIndex);// 清理包裹和仓库复制物品
                                m_StorageItemList.Add(UserItem);
                            }
                        }
                    }
                }
                m_ChallengeCreat.m_ChallengeItemList.Clear();
                if (m_ChallengeCreat.m_nChallengeGolds > 0)
                {
                    this.m_nGold += m_ChallengeCreat.m_nChallengeGolds;
                    if (M2Share.g_boGameLogGold)
                    {
                        M2Share.AddGameDataLog("36" + "\09" + this.m_sMapName + "\09" + (this.m_nCurrX).ToString() + "\09" + (this.m_nCurrY).ToString() + "\09" + this.m_sCharName
                            + "\09" + M2Share.sSTRING_GOLDNAME + "\09" + (m_ChallengeCreat.m_nChallengeGolds).ToString() + "\09" + "1" + "\09" + m_ChallengeCreat.m_sCharName);
                    }
                    m_ChallengeCreat.m_nChallengeGolds = 0;
                }
                if (m_ChallengeCreat.m_nChallengeGAMEDIAMOND > 0)
                {
                    m_nGAMEDIAMOND += m_ChallengeCreat.m_nChallengeGAMEDIAMOND;
                    if (M2Share.g_boGameLogGold)
                    {
                        M2Share.AddGameDataLog("36" + "\09" + this.m_sMapName + "\09" + (this.m_nCurrX).ToString() + "\09" + (this.m_nCurrY).ToString() + "\09" + this.m_sCharName
                            + "\09" + M2Share.g_Config.sGameDiaMond + "\09" + (m_ChallengeCreat.m_nChallengeGAMEDIAMOND).ToString() + "\09" + "1" + "\09" + m_ChallengeCreat.m_sCharName);
                    }
                    m_ChallengeCreat.m_nChallengeGAMEDIAMOND = 0;
                }
                m_ChallengeCreat.m_boChallengeOK = false;
                m_ChallengeCreat.m_WAbil.HP = m_ChallengeCreat.m_WAbil.MaxHP;
                m_ChallengeCreat.m_WAbil.MP = m_ChallengeCreat.m_WAbil.MaxMP;
                m_ChallengeCreat.HealthSpellChanged();
                m_ChallengeCreat.m_ChallengeCreat = null;
                m_ChallengeCreat.m_ChallengeLastTick = HUtil32.GetTickCount();
                if (m_ChallengeItemList.Count > 0)
                {
                    for (int i = 0; i < m_ChallengeItemList.Count; i++)
                    {
                        UserItem = (TUserItem)m_ChallengeItemList[i];
                        if (UserItem != null)
                        {
                            if (IsEnoughBag()) // 人物的包裹是否满了
                            {
                                this.m_ItemList.Add(UserItem);
                                SendAddItem(UserItem);
                            }
                            else if (m_StorageItemList.Count < Grobal2.MAXBAGITEM)
                            {
                                m_StorageItemList.Add(UserItem); // 保存到仓库里
                            }
                        }
                    }
                }
                m_ChallengeItemList.Clear();
                this.m_nGold += m_nChallengeGolds;
                m_nChallengeGolds = 0;
                m_nGAMEDIAMOND += m_nChallengeGAMEDIAMOND;
                m_nChallengeGAMEDIAMOND = 0;
                m_boChallengeOK = false;
                this.m_WAbil.HP = this.m_WAbil.MaxHP;
                this.m_WAbil.MP = this.m_WAbil.MaxMP;
                this.HealthSpellChanged();
                m_ChallengeCreat = null;
                m_ChallengeLastTick = HUtil32.GetTickCount();
                this.GoldChanged();
                this.GameGoldChanged();// 更新金刚石和金币
            }
        }
    }
}
